package global

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type LangCountry struct {
	Lang        string `json:"lang"`
	Country     string `json:"country"`
	CountryCode string `json:"country_code"`
	LangCode    string `json:"lang_code"`
}

type Comm struct {
	LangCountry
}

type PageSort struct {
	Limit     int    `json:"limit"`
	Page      int    `json:"page"`
	Total     uint   `json:"total"`
	Sortfield string `json:"sortfield"`
	Sort      string `json:"sort"`
}

func (c Comm) Success(data interface{}, lang string, msg string, unmsg string, code int, context *gin.Context) bool {

	if code == 0 {
		code = http.StatusOK
	}
	context.JSON(http.StatusOK, gin.H{
		"code":  code,
		"data":  data,
		"lang":  lang,
		"msg":   lang,
		"unmsg": lang,
	})
	return true
}
func (c Comm) Fail(msg string, unmsg string, code int, lang string, context *gin.Context) bool {

	if code == 0 {
		code = 500
	}
	context.JSON(http.StatusOK, gin.H{
		"code":  code,
		"data":  "",
		"lang":  lang,
		"msg":   msg,
		"unmsg": unmsg,
	})
	context.Next()
	return false
}
